package main

import (
	"fmt"
	"math"
)

//20ms 15%,7.8MB  15%
type MinStack struct {
	Stack, minStack []int
}

func Constructor() MinStack {
	return MinStack{
		Stack:    []int{},
		minStack: []int{math.MaxInt64},
	}
}

func (s *MinStack) Push(x int) {
	s.Stack = append(s.Stack, x)
	s.minStack = append(s.minStack, min(x, s.minStack[len(s.minStack)-1]))
}

func (s *MinStack) Pop() {
	s.Stack = s.Stack[:len(s.Stack)-1]
	s.minStack = s.minStack[:len(s.minStack)-1]
}

func (s *MinStack) Top() int {
	return s.Stack[len(s.Stack)-1]
}

func (s *MinStack) Min() int {
	return s.minStack[len(s.minStack)-1]
}

func min(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func main() {
	s := Constructor()
	s.Push(5)
	fmt.Println(s.Min())
}
